package com.scoresystem.json;

import com.scoresystem.common.CommonValue;
import com.scoresystem.exception.IllegalStateParamException;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class JsonContext {
	private JsonState state;
	
	public JsonContext(JsonState state){
		this.state=state;
	}

	public JsonState getState() {
		return state;
	}

	public void setState(JsonState state) {
		this.state = state;
	}
	/**
	 * 供上层调用访问的得到jsonobject的方法，通过不同的json状态来执行不同的下层方法
	 * @param message
	 * @param object
	 * @param arr
	 * @return
	 * @throws IllegalArgumentException
	 * @throws IllegalStateParamException
	 */
	public JSONObject getObject(String message,JSONObject object,JSONArray arr)throws
		IllegalArgumentException,IllegalStateParamException{
		if(state.getState().equals(CommonValue.STATE_SUCCESS))
			return state.getSuccessObject(message, object, arr);
		else if(state.getState().equals(CommonValue.STATE_FAILED))
			return state.getFailedObject(message);
		else
			throw new IllegalStateParamException("the state is invalid");
	}
	
}
